<include file="Public:header" />
<!--主体内容-->
<!--左边-->
<div class="centent_box">
    <include file="Public:left" />
    <!--右边-->
    <div class="centent_right_box">
        <div class="centent_right rightCon">
            <div class="Mtitle">
                <ul>
                    <li class="on"><span>房源管理</span></li>
                </ul>
                <div class="rightWord"><a href="{:U('used/add')}">新增房源</a> &gt;&gt; 数据录入</div>
            </div>
            <form id="info_form" action="{:U('Used/edit')}" method="post" enctype="multipart/form-data">
                <div class="con_div">
                    <ul class="formList width2 list_ul list_mp">
                        <li>
                            <label>房源属性：</label>
                            <select class="selectStyle" name="data[sell_type]" id="sell_type">
                                <option value="1" <if condition="$info['sell_type'] eq 1">selected</if> >出售</option>
                                <option value="2" <if condition="$info['sell_type'] eq 2">selected</if> >出租</option>
                                <option value="3" <if condition="$info['sell_type'] eq 3">selected</if> >租售</option>
                            </select>
                        </li>
                        <li>
                            <label>房源名称：</label>
                            <input type="text"  name="data[title]" class="inputStyle width3" value="{$info.title}" readonly>
                            <input type="hidden"  name="id" value="{$info.id}" >
                            <input type="hidden"  name="data[dict_id]" value="{$info.dict_id}" >
                        </li>
                        <li>
                            <label>房源编码：</label>
                            <input type="text"  name="data[encoded]" id="encoded" class="inputStyle width3" value="{$info.encoded}" >
                        </li>
                        <li>
                            <label>楼栋：</label>
                            <input type="text"  name="build[alias]"  class="inputStyle width5" value="{$dict.balias}" data="{$dict.balias}">
                            <input type="hidden"  name="build[bid]" value="{$dict.bid}">
                            <if condition="$unit_count gt 1">
                                <label>单元：</label>
                                <input type="text"  name="unit[alias]" class="inputStyle width5" value="{$dict.ualias}" data="{$dict.ualias}">
                            </if>
                            <input type="hidden"  name="unit[unid]" value="{$dict.unid}">
                            <label>楼层：</label>
                            <input type="text"  name="room[f_alias]" class="inputStyle width5" value="{$dict.f_alias}" data="{$dict.f_alias}">
                            <label>门牌：</label>
                            <input type="text"  name="room[alias]" class="inputStyle width5" value="{$dict.alias}" data="{$dict.alias}">
                            <span class="tip">（房号：<em id="roomno">{$dict.f_alias}{$dict.alias}</em>）</span>
                            <input type="hidden"  name="room[rid]" value="{$dict.rid}">
                            <input type="hidden"  name="room[floor]" value="{$dict.floor}">
                        </li>
                        <li>
                            <label>选择户型：</label>
                            <input type="number"  name="chamber" value="{$info.chamber}" class="inputStyle used_type" style="width: 50px" min="0" max="100" >
                            <span class="tip">室</span>
                            <input type="number"  name="hall" value="{$info.hall}" class="inputStyle used_type" style="width: 50px" min="0" max="100" value="0">
                            <span class="tip">厅</span>
                            <input type="number"  name="toilet" value="{$info.toilet}" class="inputStyle used_type" style="width: 50px" min="0" max="5" value="0">
                            <span class="tip">卫</span>
                            <input type="number"  name="kitchen" value="{$info.kitchen}" class="inputStyle used_type" style="width: 50px" min="0" max="5" value="0">
                            <span class="tip">厨</span>
                            <input type="number"  name="balcony" value="{$info.balcony}" data="{$info.balcony}" class="inputStyle used_type" style="width: 50px" min="0" max="5" >
                            <span class="tip">阳台</span>
                        </li>
                        <li class="dict-info">
                            <label>面积：</label>
                            <input type="text" class="inputStyle width2 required" name="room[area]" value="{$info.area}" id="proportion" >
                            <span class="tip">平方米</span>

                        </li>
                        <li id="li-total" <if condition="$info['sell_type'] neq 1 and $info['sell_type'] neq 3">style="display:none"</if>>
                            <label>总价：</label>
                            <input type="text" class="inputStyle width2 required" name="data[total_price]" id="total" value="{$info.total_price}">
                            <span class="tip">万/平方米</span>
                            <label class="label1">均价：</label>
                            <input type="text" class="inputStyle width2" name="data[average_price]"  value="{$info.average_price}" id="average" readonly>
                            <span class="tip">万/平方米</span>
                        </li>
                        <li id="li-rental" <if condition="$info['sell_type'] neq 2 and $info['sell_type'] neq 3">style="display:none"</if>>
                            <label>租金：</label>
                            <input type="text" class="inputStyle width2 required" name="data[rental_price]" id="rental" value="{$info.rental_price}">
                            <span class="tip">元/平方米</span>
                        </li>
                        <li id="contacts">
                            <label>联系人 ：</label>
                            <input type="text" class="inputStyle width1 required" name="data[contacts]" value="{$info.contacts}">
                            <span class="tip">必填项</span>
                        </li>
                        <li id="phone-li" class="clear">
                            <label>联系电话：</label>
                            <div id="proprietor" style="background-color: #EFEFF4;margin-bottom: 20px;">
                                <span style="float:right;margin-right: 700px">
                                    <button onclick="addPhone (this,{$info.id})" id="btu-phone" >新增</button>
                                </span>
                                <span>
                                    <a href="javascript:void(0);" style="color:red;display: inline;width: 100px;" onclick="view(this,{$info.id},'phone')" >点击查看</a>
                                </span>
                            </div>
                        <li style="display: none;" id="phone-other">
                            <label>其它电话：</label>
                            <input type="text" class="inputStyle required ismobile" name="phone-1" style="width:150px;margin-right: 20px;display: none" id="phone1">
                            <input type="text" class="inputStyle required ismobile" name="phone-2" style="width:150px;margin-right: 20px;display: none" id="phone2">
                            <input type="text" class="inputStyle required ismobile" name="phone-3" style="width:150px;margin-right: 20px;display: none" id="phone3">
                        </li>
                        </li>
                        <li class="li_radio">
                            <label class="lw90">朝向：</label>
                            <input type="radio" name="room[aspect]" id="orientations109" value="10" <if condition="$info['aspect'] eq 10">checked</if> >
                            <label for="orientations109">西北</label>
                            <input type="radio" name="room[aspect]" id="orientations108" value="9" <if condition="$info['aspect'] eq 9">checked</if> >
                            <label for="orientations108">西南</label>
                            <input type="radio" name="room[aspect]" id="orientations107" value="8" <if condition="$info['aspect'] eq 8">checked</if> >
                            <label for="orientations107">东北</label>
                            <input type="radio" name="room[aspect]" id="orientations106" value="7" <if condition="$info['aspect'] eq 7">checked</if> >
                            <label for="orientations106">东南</label>
                            <input type="radio" name="room[aspect]" id="orientations105" value="6" <if condition="$info['aspect'] eq 6">checked</if> >
                            <label for="orientations105">南北</label>
                            <input type="radio" name="room[aspect]" id="orientations104" value="5" <if condition="$info['aspect'] eq 5">checked</if> >
                            <label for="orientations104">东西</label>
                            <input type="radio" name="room[aspect]" id="orientations103" value="4" <if condition="$info['aspect'] eq 4">checked</if> >
                            <label for="orientations103">北</label>
                            <input type="radio" name="room[aspect]" id="orientations102" value="3" <if condition="$info['aspect'] eq 3">checked</if> >
                            <label for="orientations102">南</label>
                            <input type="radio" name="room[aspect]" id="orientations101" value="2" <if condition="$info['aspect'] eq 2">checked</if> >
                            <label for="orientations101">西</label>
                            <input type="radio" name="room[aspect]" id="orientations100" value="1" <if condition="$info['aspect'] eq 1">checked</if> >
                            <label for="orientations100">东</label>
                        </li>
                        <li class="li_checkbox" id="mating">
                            <label class="lw90">房屋配套：</label>
                            <input type="checkbox" name="mating[]" id="mating1" value="1" <if condition="in_array ('1',$info['mating'])">checked</if> ><label for="mating1">冰箱</label>
                            <input type="checkbox" name="mating[]" id="mating2" value="2" <if condition="in_array ('2',$info['mating'])">checked</if> ><label for="mating2">床</label>
                            <input type="checkbox" name="mating[]" id="mating3" value="3" <if condition="in_array ('3',$info['mating'])">checked</if> ><label for="mating3">衣橱</label>
                            <input type="checkbox" name="mating[]" id="mating4" value="4" <if condition="in_array ('4',$info['mating'])">checked</if> ><label for="mating4">热水器</label>
                            <input type="checkbox" name="mating[]" id="mating5" value="5" <if condition="in_array ('5',$info['mating'])">checked</if> ><label for="mating5">沙发</label>
                            <input type="checkbox" name="mating[]" id="mating6" value="6" <if condition="in_array ('6',$info['mating'])">checked</if> ><label for="mating6">电视</label>
                            <input type="checkbox" name="mating[]" id="mating7" value="7" <if condition="in_array ('7',$info['mating'])">checked</if> ><label for="mating7">网络</label>
                            <input type="checkbox" name="mating[]" id="mating8" value="8" <if condition="in_array ('8',$info['mating'])">checked</if> ><label for="mating8">家电齐全</label>
                            <input type="checkbox" name="mating[]" id="mating9" value="9" <if condition="in_array ('9',$info['mating'])">checked</if> ><label for="mating9">家私齐全</label>
                        </li>
                        <if condition="$info['img'] neq null">
                            <li style="height: 52px" id="used-type">
                                <label>户型图：</label>
                                <div style="display:inline-table;width: 200px;height: 200px">
                                    <img src="{$info.img}" width="50px" height="50px"/>
                                </div>
                                <button onclick="alter (this)">修改</button>
                            </li>

                        <else />
                            <li>
                                <label>户型图：</label>
                                <input type="file" name="img" id="img">
                            </li>

                        </if>
                        <li>
                            <label>产权：</label>
                            <select name="data[property]" id="property" class="selectStyle">
                                <option value="0" selected>请选择</option>
                                <option value="15" <if condition="$info['property'] eq 15">selected</if> >红本五年一套</option>
                                <option value="16" <if condition="$info['property'] eq 16">selected</if> >红本两年多套</option>
                                <option value="17" <if condition="$info['property'] eq 17">selected</if> >贷款五年一套</option>
                                <option value="18" <if condition="$info['property'] eq 18">selected</if> >贷款两年多套</option>
                                <option value="19" <if condition="$info['property'] eq 19">selected</if> >贷款不满两年</option>
                                <option value="21" <if condition="$info['property'] eq 21">selected</if> >红本不满两年</option>
                                <option value="12" <if condition="$info['property'] eq 12">selected</if> >红本在手</option>
                            </select>
                            <label>用途：</label>
                            <select name="data[purpose]" id="purpose" class="selectStyle">
                                <option value="0">请选择</option>
                                <option value="1" <if condition="$info['purpose'] eq 1">selected</if>>住宅</option>
                                <option value="2" <if condition="$info['purpose'] eq 2">selected</if>>写字楼</option>
                                <option value="3" <if condition="$info['purpose'] eq 3">selected</if>>商铺</option>
                                <option value="4" <if condition="$info['purpose'] eq 4">selected</if>>商务公寓</option>
                                <option value="5" <if condition="$info['purpose'] eq 5">selected</if>>厂房</option>
                            </select>
                        </li>
                        <li>
                            <label>钥匙人 ：</label>
                            <select name="data[keyer]" id="keyer" class="selectStyle">
                                <option value="">请选择</option>
                                <volist name="users" id="vo">
                                    <option value="{$vo.id}" {$vo.key_sele}>{$vo.username}</option>
                                </volist>
                            </select>
                            <label>钥匙编号 ：</label>
                            <input type="text" class="inputStyle width1" name="data[keyno]" value="{$info.keyno}">
                        </li>
                        <li>
                            <label>维护人 ：</label>
                            <input type="text" class="inputStyle width2" name="maintain" value="{$maintain}" id="maintain" readonly>
                            <button onclick="grab ({$info.id},{$info.user_id},'{$info.add_time}')" style="width:60px;height: 32px;margin-left: 30px">抢 回</button>
                        </li>

                        <if condition="$info['files'] eq null">
                            <li id="files">
                                <label>室内图：</label>
                                <script id="uploadpic" name="uploadpic" type="text/plain"></script>
                                <input type="button" class="btn btn_submit" style="margin:0 0 10px 10px;" onclick="upImage();" value="选择图片">
                                <div id="imageList">
                                    <ul class="list clearfix"></ul>
                                </div>
                                <input type="hidden" name="file" id="file" />
                            </li>
                        <else/>
                            <li style="height: 52px" id="m_img">
                                <label>室内图：</label>
                                <div style="display:inline-table;height: 200px" >
                                    <volist name="info['files']" id="vo">
                                        <span style="float:left;margin-left: 20px"><a href="{$vo->img}" class="lightbox" rel="list2"><img src="{$vo->img}" width="50px" height="50px" /></a></span>
                                    </volist>
                                </div>
                            </li>
                            <li id="files">
                                <label>上传室内图：</label>
                                <script id="uploadpic" name="uploadpic" type="text/plain"></script>
                                <input type="button" class="btn btn_submit" style="margin:0 0 10px 10px;" onclick="upImage();" value="选择图片">
                                <div id="imageList">
                                    <ul class="list clearfix"></ul>
                                </div>
                                <input type="hidden" name="file" id="file" />
                            </li>
                        </if>

                        <li class="li_radio">
                            <label class="lw90">装修情况：</label>
                            <input type="radio" name="data[decorate]" id="renovation_type70" value="4" <if condition="$info['decorate'] eq 4">checked</if> ><label for="renovation_type70">豪装</label>
                            <input type="radio" name="data[decorate]" id="renovation_type68" value="3" <if condition="$info['decorate'] eq 3">checked</if> ><label for="renovation_type68">精装</label>
                            <input type="radio" name="data[decorate]" id="renovation_type67" value="2" <if condition="$info['decorate'] eq 2">checked</if> ><label for="renovation_type67">简装</label>
                            <input type="radio" name="data[decorate]" id="renovation_type69" value="1" <if condition="$info['decorate'] eq 1">checked</if> ><label for="renovation_type69">毛坯</label>
                        </li>
                        <div>
                            <li>
                                <label>年代&地址：</label>
                                <input type="text" name="data[address]" value="点击展开......" onclick="spread(this)" readonly>
                            </li>
                            <div style="display: none" id="spread">
                                <li>
                                    <label>建筑年代：</label>
                                    <input type="text" class="inputStyle width2" name="data[years]" value="{$info.years}" id="years" readonly>
                                    <span class="tip">年</span>
                                </li>
                                <li>
                                    <label>所在地址：</label>
                                    <input type="text" class="inputStyle width3" name="data[address]" value="{$info.address}" id="addr" readonly>
                                    <span class="tip">中文字符</span>
                                </li>
                                <li>
                                    <label>地图标注：</label>
                                    <input type="text" class="inputStyle" name="data[map]" id="map" value="{$info.map}" readonly>
                                </li>
                            </div>
                        </div>

                        <li class="height2">
                            <label>详细介绍：</label>
                            <textarea name="data[info]" id="info" style="width:100%;height:300px;resize: none;float:left">{$info.info}</textarea>
                        </li>
                        <input type="hidden"  name="data[img]" id="img-url">
                        <div class="follow">
                            <h1 style="font-size:1.5em;color:dimgrey">跟进信息：</h1>
                            <dl class="follow clear" style="background-color: #7AD8F5">
                                <volist name="m_follows" id="fo">
                                    <dt>
                                    <h1>{$fo.add_time|date='Y-m-d H:i:s',###}</h1>
                                    <p>{$fo.discuss} <span>{$fo.uname}</span></p>
                                    <hr />
                                    </dt>
                                </volist>
                            </dl>
                            <div></div>
                            <dl class="follow clear">
                                <volist name="a_follows" id="fo">
                                    <dt>
                                    <h1>{$fo.add_time|date='Y-m-d H:i:s',###}</h1>
                                    <p>{$fo.discuss} <span>{$fo.uname}</span></p>
                                    <hr />
                                    </dt>
                                </volist>
                            </dl>
                        </div>
                        <li>
                            <input type="submit" value="保 存" class="btnStyle">
                            <button class="btnStyle" onclick="del()">删 除</button>
                            <button class="btnStyle" onclick="follow()">跟 进</button>
                            <button class="btnStyle" onclick="deal()">成 交</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
</div>
<js file="__S__/ueditor/ueditor.config.js" charset="utf-8" />
<js file="__S__/ueditor/ueditor.all.min.js" charset="utf-8" />
<js file="__S__/ueditor/lang/zh-cn/zh-cn.js" charset="utf-8" />
<js file="__JS__/uploadImg.js" charset="utf-8" />
<script type="text/javascript">
    window.UEDITOR_HOME_URL='__STATIC__/ueditor/';
    window.onload=function(){
        window.UEDITOR_CONFIG.initialFrameWidth=880;
        window.UEDITOR_CONFIG.initialFrameHeight=500;
        upmoreimg();
    }
    var ue = UE.getEditor('info', {
        toolbars: [[
            'fullscreen', 'source', '|',
            'bold', 'italic', 'underline', '|', 'fontfamily','fontsize', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', 'simpleupload','|', 'kityformula', 'preview'
        ]]
    });
</script>
<script src="__S__/js/ajaxfileupload.js"></script>
<script src="__S__/js/jquery.validate.js"></script>
<script src="__S__/js/magess.js"></script>
<script src="__S__/js/jquery.metadata.js"></script>
<script type="text/javascript">
    $().ready(function() {
        $("#info_form").validate();
        jQuery.validator.addMethod("ismobile", function(value, element) {
            var length = value.length;
            var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
            return this.optional(element) || (length == 11 && mobile.test(value));
        }, "请正确填写您的手机号码");
        //图片放大
        $('.lightbox').lightbox();
    });

</script>
<script>
    $("#sell_type").change (function (){
        var id = $(this).val();
        if (id == 1){
            $('#li-rental').hide();
            $('#li-total').show();
        }
        if (id == 2){
            $('#li-rental').show();
            $('#li-total').hide();
        }
        if (id == 3){
            $('#li-rental').show();
            $('#li-total').show();
        }
    });
    var usedid = "{:I('get.id')}";
    $('#info_form').on("change","#img",function(e){
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/Ajaxupload')}";
            var id = $("input[name='room[rid]']").val();
            $.ajaxFileUpload
            (
                    {
                        url: url,
                        secureuri: false,
                        data:{rid:id},
                        fileElementId: 'img',
                        dataType: 'json',
                        success: function (data, status)
                        {
                            $('#img-url').val(data.data.img);
                            $('#img').parent('li').remove();
                            var html = '<li style="height: 220px" id="used-type"><label>户型图：</label><div style="display:inline-table;width: 200px;height: 200px"><img src="'+data.data.img+'" width="200px" height="200px"/> </div> <button onclick="alter (this)">修改</button></li>';
                            $('#mating').after(html)
                            layer.closeAll();
                        },
                        error: function (data, status, e)
                        {
                            layer.msg('上传失败', {icon: 0});
                        }
                    }
            )

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    })
    $("input[name='build[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='build[bid]']").val();
            var alias = $("input[name='build[alias]']").val();
            var data = {id:id,val:alias,table:'build',type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='build[bid]']").val();
            var alias = $("input[name='build[alias]']").val();
            var data = {id:id,val:alias,table:'build',type:'alias',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='unit[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='unit[unid]']").val();
            var alias = $("input[name='unit[alias]']").val();
            var data = {id:id,val:alias,table:'unit',type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='unit[unid]']").val();
            var alias = $("input[name='unit[alias]']").val();
            var data = {id:id,val:alias,table:'unit',type:'alias',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[f_alias]']").change(function(){
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[f_alias]']").val();
            var data = {id:id,val:alias,table:'room',type:'f_alias',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        var room = $("input[name='room[alias]']").val();
                        $('#roomno').html(alias+room);
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[alias]']").val();
            var floor = $("input[name='room[floor]']").val();
            var data = {id:id,val:alias,table:'room',floor:floor,type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg(response.msg, {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[alias]']").val();
            var floor = $("input[name='room[floor]']").val();
            var f_alias = $("input[name='room[f_alias]']").val();
            var data = {id:id,val:alias,table:'room',floor:floor,type:'alias',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        $('#roomno').html(f_alias+alias);
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[area]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[area]']").val();
            var data = {id:id,val:alias,table:'room',type:'area'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            $('#total').val(0.00);
            $('#average').val(0.00);
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[area]']").val();
            var data = {id:id,val:alias,table:'room',type:'area',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$room.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[aspect]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[aspect]']:checked").val();
            var data = {id:id,val:alias,table:'room',type:'aspect'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            $('#total').val(0.00);
            $('#average').val(0.00);
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[aspect]']:checked").val();
            var data = {id:id,val:alias,table:'room',type:'aspect',usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    $('.used_type').change(function (){
        var tar = $(this);
        var lastVal = $(this).attr ('data');
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = tar.val();
            var type = tar.prop('name');
            var data = {id:id,val:alias,table:'room',type:type}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = tar.val();
            var type = tar.prop('name');
            var data = {id:id,val:alias,table:'room',type:type,usedid:usedid}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    /*$("#img").change(function (){
     layer.confirm('值已改变，是否更新到数据字典！', {
     btn: ['是','否']
     }, function(){
     $('#total').val(0.00);
     $('#average').val(0.00);
     var url = "{:U ('Ajax/setDict')}";
     var id = $("input[name='room[rid]']").val();
     var alias = $("input[name='room[aspect]']:checked").val();
     var data = {id:id,val:alias,table:'room',type:'aspect'}
     $.ajax({
     type : "post", url : url, data : data, dataType : 'json', async : false,
     success : function(response){
     if (response.state == 'ok'){
     layer.msg('更新成功！', {icon: 1});
     }else{
     layer.msg('更新失败！', {icon: 0});
     }
     }
     });

     }, function(){
     $('#proportion').val("{$unit.area}");
     layer.msg('已取消！', {icon: 0});
     });
     });*/
    $('#total').keyup(function(){
        var total = $(this).val();console.log(total);
        var area = $('#proportion').val();console.log(area);
        var average = parseFloat(total)/parseFloat(area)*10000;
        $('#average').val(average.toFixed(2));
    })
    //新增电话号码
    function addPhone (tar,usedid){
        event.preventDefault();//阻制默认事件
        window.event.returnValue;
        layer.open({
            type: 1,
            area: ['300px', ''],
            anim: 2,
            content: '<div style="margin-top: 20px"><ul class="formList list_ul clear">' +
            '<li><label>手机号：</label><input type="number" name="phone" class="inputStyle width2 ismobile" /></li>' +
            '</ul><div style="margin:50px 10px 10px 100px">' +
            '<button onclick="confirm ('+usedid+')">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
            '<button onclick="javascripy:layer.closeAll()">取消</button>' +
            '</div></div>'
        });
    }
    var phoneCount = 0;
    function confirm(usedid){
        var phone = phone = $('input[name="phone"]').val();
        var url = "{:U('Ajax/Addphone')}";
        var data = {usedid:usedid,phone:phone};
        $.post (url, data, function (reponse){
            if (reponse.state == 'ok'){
                phoneCount += 1;
                $('#phone-other').show ();
                $('#phone'+phoneCount).show ();
                $('#phone'+phoneCount).val(phone);
                layer.msg(reponse.msg,{icon: 1});
            }else{
                layer.msg(reponse.msg,{icon: 0});
            }
        },'json');
        var index = layer.index;
        layer.close(index);
    }
    function alterPhone (field, usedID, phone){
        var html = '<div style="margin-top: 20px"><ul class="formList list_ul clear">';
        html += '<div style="margin-top: 20px"><ul class="formList list_ul clear">' +
                '<li><label>手机号：</label><input type="number" name="phone1" value="'+phone+'" class="inputStyle width2" id="'+field+'" /></li>' +
                '</ul><div style="margin:50px 10px 10px 100px">' +
                '<button onclick="phone(this,\''+field+'\','+usedID+')">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
                '</div></div> ';
        layer.open({
            type: 1,
            title: '填写信息',
            area: ['300px', ''],
            content: html
        });
    }
    function phone (tar,field,usedid){
        var phone = $('input[name="phone1"]').val();
        var url = "{:U('Ajax/Editphone')}";
        var data = {field:field,usedid:usedid,phone:phone};
        $.post (url, data, function (reponse){
            if (reponse.state == 'ok'){
                $('#'+field).html (phone);
                layer.msg('设置成功',{icon: 1});
            }else{
                layer.msg('设置失败',{icon: 0});
            }
        },'json');




        var index = layer.index;
        layer.close(index);
    }
    function alter (tar){
        event.preventDefault();
        window.event.returnValue;
        var prevElem = $('#used-type').prev('li');
        $('#used-type').remove();
        prevElem.after('<li><label>户型图：</label><input type="file" name="img" id="img"></li>');
        layer.closeAll();
    }
    function grab (usedId,uid,time){
        event.preventDefault();
        window.event.returnValue;
        var url = "{:U('Ajax/setMaintain')}";
        var data = {usedid:usedId,uid:uid,type:1,time:time};
        $.post (url, data, function (response){
            var data = response.data;
            if (response.state == 'ok'){
                $('#maintain').val (data.username);
                layer.msg(response.msg, {icon: 1});
            }else{
                layer.msg(response.msg, {icon: 0});
            }
        },'json');


    }

    //电话查询
    $('input[name="data[phone]"]').change(function (v){
        var phone = $(this).val ();
        var url = "{:U('Ajax/getPhone')}";
        var data = {phone:phone};
        $.post (url, data, function (response){
            var data = response.data;
            var link = "{:U('used/edit')}";
            if (response.state == 'ok'){
                var html = '<div><ul>';
                $.each (data, function (i,v){
                    html += '<li><a href="'+link+'&id='+v.id+'" style="height: 30px;font-size: 16px;text-align: center" target="_blank">'+v.title+'<em style="' +
                            'color:#A8A8A8;font-size: 10;">('+v.balias+v.ualias+'单元'+v.alias+')</em></a></li>';
                });
                html += '</ul></div>'
                layer.open({
                    type: 1,
                    area: ['300px', ''],
                    anim: 2,
                    content: html
                });
            }
        },'json');

    });
    //删除
    function del(){
        event.preventDefault();
        window.event.returnValue;
        window.location.href = "{:U('del')}&id="+usedid;
    }
    //跟进
    function follow(){
        event.preventDefault();
        window.event.returnValue;
        layer.open({
            type: 1,
            title:'填写信息',
            area: ['500px', '270px'],
            content: '<div style="">' +
            '<textarea id="cont" cols="79.5" rows="11" style="margin-left: 1px;"/><br/>' +
            '<button onclick="submit_btn(this)" style="margin: 10px 10px 10px 230px">提交</button>' +
            '</div>'
        });
    }
    function submit_btn (tar){
        var conter = $('#cont').val();
        var url = "{:U('used/follow')}";
        var user_id="{$info.user_id}",used_id="{$info.id}";
        var data = {user_id:user_id,used_id:used_id,conter:conter}
        $.post(url,data,function (reponse){
            if (reponse = 'ok'){
                layer.msg('提交成功');
                window.location.reload(1);
            }else{
                layer.msg('提交失败');
            }
        },'text');
    }
    //成交房源
    function deal (){
        event.preventDefault();
        window.event.returnValue;
        window.location.href = "{:U('Deal/bargain')}&id="+usedid;
    }
    //查看业主手机
    function view (tar,used_id,id){
        var url = "{:U('Ajax/view')}", data = {used_id:used_id,field:id};
        $.post(url, data, function (reponse){
            var data = reponse.data;
            var follow = reponse.follow;
            var html = '<div style="padding: 20px 20px">';
            if(reponse.state == 1){
                var c = 1;
                var elementID = '';
                $.each (data, function (i, v){
                    if (c ==1) elementID = 'phone';
                    if (c ==2) elementID = 'phone1';
                    if (c ==3) elementID = 'phone2';
                    if (c ==4) elementID = 'phone3';
                    html += '<div><span>业主'+c+'：<em id="'+elementID+'">'+v+'</em> </span><span style="margin-left: 50px"><button onclick="alterPhone (\''+i+'\','+used_id+','+v+')">修 改</button></span></div>';
                    c++;
                });
                html += '<div style="background-color: #EFEFF4;padding: 20px 20px;"><div style="font-size: 20px; margin-bottom: 10px">浏览信息：</div><ul>';
                $.each (follow, function (i, v){
                    html += '<li style="color:#B3B3B3;font-size: 12px;">'+v.add_time+'&nbsp;&nbsp;'+v.uname+'&nbsp;&nbsp;'+v.discuss+'</li>';
                });
                html += '</ul></div></div>';
                layer.open({
                    type: 1,
                    title:'业主信息',
                    area: ['500px', ''],
                    content: html
                });

            }else if(reponse.state == 3){
                var str = '<span>您有未完成的<a href="{:U(edit)}&id='+data.used+'" style="display: inline;color:blue"> 跟进</a>, 请您完成后再查看</span>'
                $('#proprietor').html (str);
            }else{
                $('#proprietor').html (reponse.text);
            }
        }, 'json');

    }
    function spread(tar){
        $(tar).parent('li').hide();
        $('#spread').show();
    }
</script>
<include file="Public:footer" />